﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DrSoftsFrame.Servers;

namespace PreeRegisterDAL
{
    public class DoctorUpdateDAL
    {
        public static DataSet GetDoctorUpdateInfo(string doctorid)
        {
            try
            {
                string sqlstr = string.Format(@"select  b.no_staff,b.staffcode,b.staffname,b.no_sex,b.no_dept,c.DeptName
                                                from dictstaff b 
                                                join dictdept c on b.no_dept=c.no_dept
                                                where b.no_staff={0}", doctorid);
                ClinicDb mydb = new ClinicDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                ds.Tables[0].TableName = "DictStaff";
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }

        public static DataSet GetDoctorInfoByDeptId(string deptid)
        {
            try
            {
                //刘鹏林   2015-10-23 修改只获取有排班的医生  预约天数内的医生  最大号和预约最大号不为空的医生 
                //去掉最大预约号大于0限制，排班日期可从当前日期-1至未来15日  liujia151104
                //根据科室ID先取对应排班，然后反查医师,解决所属A科室而出诊为B科室的医师查询不到的问题。 liujia151120
                string sqlstr = string.Format(@"select distinct a.No_Staff,a.StaffName from DictStaff a
                                                join OPDWorkPerson b on a.No_Staff=b.iPersonID
                                                join opdworkplan c on a.No_Staff=c.iPersonID
                                                where c.iDeptID={0} and b.bDoctorFlag=1 and c.dStartTime between getdate()-1 and DATEADD(d,15,getdate())  
                                                and  isnull(nMaxDiagnoseNum,0) >0 ", deptid);
                ClinicDb mydb = new ClinicDb();
                DataSet ds = mydb.ExecuteSelect(sqlstr);
                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                ds.Tables[0].TableName = "DictStaff";
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
